home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / develop / libsrc11.arc / MODL.S < prev    next >
Text File  |  1989-04-27  |  1KB  |  58 lines

  1. ******************************************************************************
  2. * modl.s 3.1 11/12/84 
  3. *
  4. *        68HC11 CROSS C COMPILER RUN-TIME LIBRARY
  5. *
  6. *           (c) Copyright 1984, Motorola, Inc.
  7. *
  8. *  FUNCTION NAME:    .modl
  9. *
  10. *  ACTION:        Calculate the modulus of two 16-bit signed integers.
  11. *
  12. *  REGISTERS AND STACK:
  13. *
  14. *  ON ENTRY:    X:    FP (frame pointer)
  15. *        D:    Dividend
  16. *        Y:    Divisor
  17. *
  18. *        STACK:      Return Address
  19. *        SP:    
  20. *
  21. *  ON EXIT:    X:    FP 
  22. *        D:    Modulus
  23. *
  24. *        STACK:    Previous Contents
  25. *        SP:    
  26. *
  27. ******************************************************************************
  28.     psct
  29.     xdef    .modl
  30. .modl:
  31.     pshx        save FP
  32.     psha        sign of dividend
  33.     tsta        is dividend > 0?
  34.     bpl    mod1    yes
  35.     coma        no..negate
  36.     comb
  37.     addd    #1
  38. mod1:    pshy        copy divisor
  39.     pulx        ..to X
  40.     cpx    #0    is divisior > 0?
  41.     bpl    mod2    yes
  42.     xgdx        no..negate
  43.     coma
  44.     comb
  45.     xgdx
  46.     inx
  47. mod2:    idiv        do division D/X
  48.     tsx        use X to access sign byte
  49.     tst    0,%x    is sign positive?
  50.     bpl    mod3    yes
  51.     coma        no..negate
  52.     comb
  53.     addd    #1
  54. mod3:    ins        discard sign byte
  55.     pulx        restore FP
  56.     rts        return
  57.     end
  58.